﻿using System;
using System.Drawing;
using System.Windows.Forms;
using Felbot.Profiles;

namespace Felbot.Interface {
    /// <summary>This form allows the user to select a/some profile(s) to open.</summary>
    public partial class frmOpenProfile : Form {
        /// <summary>Creates a new open profile selection dialog.</summary>
        /// <param name="main">The parent form.</param>
        public frmOpenProfile() {
            InitializeComponent();
            LoadProfileList();
        }

        private void LoadProfileList() {
            ListViewItem item;
            string status;
            Color color;
            foreach (Profile profile in ProfileControl.ProfileList) {
                if (profile.Open) {
                    status = "Open";
                    color = Color.Gray;
                } else {
                    status = "Closed";
                    color = Color.White;
                }
                item = new ListViewItem(new string[] { profile.ProfileName, status });
                item.ForeColor = color;
                lvProfiles.Items.Add(item);
            }
        }

        private void lvProfiles_SelectedIndexChanged(object sender, EventArgs e) {
            btnOpen.Enabled = (lvProfiles.SelectedItems.Count >= 1 && (!(lvProfiles.SelectedItems.Count == 1 && lvProfiles.SelectedItems[0].ForeColor != Color.White)));
        }

        private void btnOpen_Click(object sender, EventArgs e) {
            foreach (ListViewItem lvItem in lvProfiles.SelectedItems) {
                if (lvItem.ForeColor == Color.White) {
                    Program.MainForm.OpenProfile(lvItem.Text);
                    this.Close();
                }
            }
        }

        private void btnCancel_Click(object sender, EventArgs e) {
            this.Close();
        }
    }
}
